#!/bin/sh

## hyphop ##

#= make kresq image

PR=$(dirname $0)
RP=$(realpath $PR)

cd "$PR" || exit 1

. ./build.conf

[ "$BOARDS" ] || BOARDS="$@"
[ "$BOARDS" ] || \
BOARDS="VIM1 VIM2 VIM3 VIM3L Edge"

TIME=$(date +%s)
DATE=$(tz= date -R -d"@$TIME")

KLABEL="UBOOT"
klabel="uboot"

NAME="Khadas.$KLABEL.mainline"

./download $MAKE_IMAGE_URL "" $DOWNLOADS #

for x in $DOWNLOADS/make_image; do
    [ -s $x ] || continue
    [ -x $x ] || chmod 0777 $x
    make_image=$(realpath "$x")
done

[ "$make_image" ] || FAIL make_image not found

# config name must start from .
# for CONFIG in $MNT/.*.image.conf $MNT/.meta/.*.image.conf ""; do

KRESQ_CONF=/tmp/.krescue.$KLABEL.image.conf
DESC_ADD=$(cd $UBOOT_DIR2; grep "" *.version)
. ./krescue.image.conf.tpl > $KRESQ_CONF

cd $UBOOT_DIR2

OUT=$UBOOT_DIR2 \
    $make_image $KRESQ_CONF
